<?php
class Admin_model extends CI_Model {
	

	public function __construct()
	{
		$this->load->database();
	}
	
	
	function check_login()
    {
		$this->load->helper('url');
		//
        $query = null; // emptying in case 
		//
		$promotion	= 'Promotion Name'; 		// hard-coded or set in config file
        $email 		= $_POST['email'];
		$password 	= $_POST['password'];
		$date	 	= date('Y-m-d H:i:s');	// NOW() replacement

		// select
        $query = $this->db->get_where('users', array( // matching criteria array
            'email' => $email,
			'password' => $password
        ));
		
		// count
        $count = $query->num_rows(); // counting result from query
		
		// if user DO exist
        if ($count === 0) 
		{
			//echo "user does not exists";
			return FALSE;
		}
		else
		{
			$data = array(
				'date' 	=> $date, // update with date of latest entry
				);
			$this->db->where('email', $email);
			$this->db->update('users', $data); 
			//
			if($this->db->affected_rows() > 0)
			{
			  	// if updating completed succsessfully, redirect administrator to Entries page.
				//
				return TRUE;
			}
		}
	}
}